package hotelManagement.hotelArtifacts;

import java.util.List;
import org.springframework.orm.hibernate3.support.*;

public class CustomerInfoDaoImpl extends HibernateDaoSupport implements CustomerInfoDao{
	
	public void save(CustomerInfo customerInfo){
		getHibernateTemplate().save(customerInfo);
	}
	
	public void update(CustomerInfo customerInfo){
		getHibernateTemplate().update(customerInfo);
	}
	
	public void delete(String personId){
		getHibernateTemplate().delete(getById(personId));
	}
	
	public CustomerInfo getById(String personId){
		return (CustomerInfo)getHibernateTemplate().get(CustomerInfo.class, personId);
	}
	
	public CustomerInfo getByUserName(String userName){
		List<CustomerInfo> ci = getHibernateTemplate().find("from CustomerInfo c where c.userName='" + userName + "'");
		if(ci.size()==0)
			return null;
		return ci.get(0);
	}
	
	public List<CustomerInfo> getAll(){
		return getHibernateTemplate().find("from CustomerInfo");
	}

}
